<?php
/**
 * Created by PhpStorm.
 * User: xiatong
 * Date: 2018/9/25
 * Time: 下午9:26
 */

namespace app\store\controller;

use app\store\model\Recharge as RechargeModel;
class Recharge extends Controller
{

    public function recharge_list(){

        $model =new RechargeModel();
        $list =$model->getList();
        return $this->fetch('index',compact('list'));
    }

    public function recharge_logs(){

    }



    public function add(){
        $model = new RechargeModel();
        if (!$this->request->isAjax()) {
            return $this->fetch('add');
        }
        // 新增记录
        if ($model->add($this->postData('recharge'))) {
            return $this->renderSuccess('添加成功', url('recharge/recharge_list'));
        }
        $error = $model->getError() ?: '添加失败';
        return $this->renderError($error);
    }

    public function edit($recharge_id){
        $recharge = RechargeModel::get($recharge_id);

        if($this->request->isAjax()){
            $res = $recharge->edit($this->postData('recharge'));

            if($res){
                return $this->renderSuccess('充值卡更新成功',url('recharge/recharge_list'));
            }else{
                $error = $recharge->getError() ?: '更新失败';
                return $this->renderError($error);
            }
        }
        return $this->fetch('edit',compact('recharge'));
    }
}